package stackexchange.analyzer.evaluator;

import java.util.Vector;

import stackexchange.User;
import stackexchange.UserGroup;
import stackexchange.posts.Answer;
import stackexchange.posts.Question;
import statisticalanalysis.StatisticalAnalysis;
import static stackexchange.Constants.*;

public abstract class ExpertEvaluator {

	protected UserGroup userGroup;
	protected Vector<Question> questions;
	protected Vector<Answer> answers;
	protected UserGroup experts;

	public void setData(UserGroup userGroup, Vector<Question> questions,
			Vector<Answer> answers) {
		this.userGroup = userGroup;
		Vector<User> experts = (Vector<User>) userGroup.getUsers().clone();
		this.questions = (Vector<Question>) questions.clone();
		this.answers = (Vector<Answer>) answers.clone();
		for (int i = 0; i < experts.size(); i++) {
			double expertScore = calculateExpertScore(experts.get(i));
			experts.get(i).setExpertiseScore(expertScore);
		}
		UserGroup sortedExperts = new UserGroup(experts).sortOnExpertiseScore();

		// take %? procent

		// this.experts = sortedExperts;
		// this.experts = new UserGroup(StatisticalAnalysis.getQuartile(
		// sortedExperts.getUsers(), "getReputation", 0.98));

		Vector<User> limitedExperts = new Vector<User>();
		for (int i = 0; i < sortedExperts.getUsers().size() * PROC_OF_USERS; i++) {
			limitedExperts.add(sortedExperts.getUsers().get(i));
			// System.out.println(sortedExperts.getUsers().get(i));
		}
		this.experts = new UserGroup(limitedExperts);
	}

	abstract double calculateExpertScore(User user);

	public UserGroup getExperts() {
		return experts;
	}

	public F1Score getResult(UserGroup analyzedExperts) {
		return new F1Score(userGroup.getUsers(), analyzedExperts.getUsers(),
				experts.getUsers());
	}

}
